<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateFinancessTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('finances', function (Blueprint $table) {
            //财务记录表
            $table->bigIncrements('id');
            $table->unsignedBigInteger('seller_id')->nullable(false)->comment('商家id');
            $table->unsignedTinyInteger('type')
                ->nullable(false)
                ->default(\App\Models\Finance::TYPE_TOP_UP)
                ->comment('详见模型');
            $table->tinyInteger('is_income')
                ->nullable(false)
                ->default(true)
                ->comment('是否是收入1-是0-否');
            $table->decimal('amount', 9, 2)->nullable(false)->default(0.00)->comment('金额');
            $table->string('desc', 255)->nullable(false)->comment('备注说明');
            $table->dateTime('generated_at')->nullable()->comment('产生时间');
            $table->timestamps();
            $table->foreign('seller_id')->references('id')->on('sellers')->onDelete('cascade')->onUpdate('cascade');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('finances');
    }
}
